package way_bfs

import . "whoops/leetcode/a690_员工的重要性/answer/common"

func GetImportance(employees []*Employee, id int) int {
	sum := 0
	resultMap := make(map[int]*Employee, 0)
	for _, employee := range employees {
		resultMap[employee.Id] = employee
	}
	queue := []int{id}
	for len(queue) > 0 {
		employee := resultMap[queue[0]]
		queue = queue[1:]
		sum += employee.Importance
		for _, subId := range employee.Subordinates {
			queue = append(queue, subId)
		}
	}
	return sum
}
